package at.fhj.itm10.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;
import javax.swing.JTextField;

public class SearchPanel extends JPanel implements MouseListener, KeyListener,
		FocusListener
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6347288741797077610L;

	private MainWindow parent;

	// GUI elements of the search panel
	private JTextField tfSearch;

	public SearchPanel(MainWindow parent)
	{
		this.parent = parent;
		initContent();
	}

	private void initContent()
	{
		this.setLayout(new FlowLayout());
		this.tfSearch = new JTextField();
		this.tfSearch.addFocusListener(this);
		this.tfSearch.setPreferredSize(new Dimension(150, 20));
		this.setTfDescriptionText(tfSearch, "Suche");
		this.add(tfSearch);
	}

	private void setTfDescriptionText(JTextField textField, String text)
	{
		Font font = new Font("Calibri", Font.ITALIC, 15);
		textField.setFont(font);
		textField.setForeground(Color.GRAY);
		textField.setText(text);
	}

	private void setTfWritingStyle(JTextField textField)
	{
		textField.setText("");
		Font font = new Font("Calibri", Font.PLAIN, 15);
		textField.setFont(font);
		textField.setForeground(Color.BLACK);

	}

	@Override
	public void keyPressed(KeyEvent e)
	{

	}

	@Override
	public void keyReleased(KeyEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e)
	{

	}

	@Override
	public void mouseEntered(MouseEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void focusGained(FocusEvent e)
	{
		if (e.getSource().equals(this.tfSearch))
		{			
			this.setTfWritingStyle(this.tfSearch);
		}

	}

	@Override
	public void focusLost(FocusEvent e)
	{
		if (e.getSource().equals(this.tfSearch))
		{
			this.setTfDescriptionText(this.tfSearch, "Suche");
		}

	}

}
